import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_wechat/constants.dart';
import 'package:flutter_wechat/main.dart';

class DiscoveryPage extends StatefulWidget {
  final PopupMenuItemSelected<String> onSelected;

  const DiscoveryPage({this.onSelected, Key key}) : super(key: key);

  @override
  _DiscoveryPageState createState() => _DiscoveryPageState();
}

class _DiscoveryPageState extends State<DiscoveryPage> {
  List<_DiscoveryItem> _list = [
    _DiscoveryItem(title: "朋友圈", icon: Icon(friendIcon, color: Colors.lightGreen, size: 22.0)),
    _DiscoveryItem(title: "扫一扫", icon: Icon(sweepIcon, color: Colors.blue, size: 22.0)),
    _DiscoveryItem(title: "看一看", icon: Icon(seeIcon, color: Colors.orange, size: 22.0)),
    _DiscoveryItem(title: "小程序", icon: Icon(smallProgramIcon, color: Colors.purple, size: 22.0)),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getMyAppBar(onSelected: widget.onSelected, title: "发现"),
      body: Container(
        color: Color(0xffEDEDED),
        child: ListView.builder(
            itemBuilder: (context, index) => _DiscoveryItemWidget(item: _list[index]),
            itemCount: _list.length),
      ),
    );
  }
}

class _DiscoveryItemWidget extends StatelessWidget {
  final VoidCallback onTap;
  final _DiscoveryItem item;

  const _DiscoveryItemWidget({this.onTap, this.item, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      height: 58.0,
      margin: EdgeInsets.symmetric(vertical: 5.0),
      padding: EdgeInsets.symmetric(horizontal: 10.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              SizedBox(width: 5.0),
              item.icon,
              SizedBox(width: 15.0),
              Text(item.title, style: TextStyle(fontSize: 16.0),),
            ],
          ),
          Icon(Icons.chevron_right, color: Colors.grey),
        ],
      ),
    );
  }
}

class _DiscoveryItem {
  final String title;
  final Icon icon;

  _DiscoveryItem({this.title, this.icon});
}

class MyPopupMenu extends StatelessWidget {
  final String title;
  final Icon icon;

  MyPopupMenu({this.title, this.icon});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 30.0,
      child: Row(
        children: <Widget>[
          icon,
          const SizedBox(width: 10.0),
          Text(title, style: TextStyle(color: Colors.white)),
        ],
      ),
    );
  }
}
